package com.cy.springcloudalibaba.controllers;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description: 服务提供者
 * @ClassName: ProviderController
 * @Author: chenyu
 * @Date: 2025/1/10 10:29
 */
@Slf4j
@RestController
public class ProviderController {

    @GetMapping("/")
    public ResponseEntity index() {
        log.info("provider /");

        return new ResponseEntity("index", HttpStatus.OK);
    }

    @GetMapping("/echo/{app}")
    public String echo(@PathVariable String app) {
        log.info("provider01 /echo/{app}");

        return "hello nacos discover " + app;
    }

    @GetMapping("/feign/{app}")
    public String feign(@PathVariable String app) {
        log.info("provider /feign/{app}");

        return "hello nacos discover " + app;
    }



    @GetMapping("/sleep")
    public String sleep() {
        log.info("provider /sleep");
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        return "ok";
    }

    @GetMapping("/feign/divide")
    public String divide(@RequestParam Integer a, @RequestParam Integer b) {
        log.info("provider /divide");
        return String.valueOf(a / b);
    }

    @GetMapping("/feign/print")
    public String print(@RequestParam String a) {
        log.info("provider /print");
        return a;
    }
}
